﻿@model Revenue
@{
    ViewBag.Title = "收入管理维护";
    Layout = "~/Views/Shared/_LayoutFormDetail.cshtml";
}
@section Up{
    @Html.HiddenFor(model => model.Id)
    @Html.nbDropDownListFor(model => model.SiteId, "ProjectSite").Required()
    @Html.nbDateFor(model => model.Date).Required()
    @Html.nbTextBoxFor(model => model.EstimateAmount).ReadOnly()
    @Html.nbTextBoxFor(model => model.SellAmount)
    @Html.nbTextAreaFor(model => model.Remark)
}
@section Down{
    @(Html.nbDetailFor<RevenueItem>(s =>
    {
        s.ID("RevenueList");
        s.layoutW(10);
        s.layoutH(240);
        s.Columns(col =>
        {
            col.Bind(e => e.Id).IsKey();
            col.Bind(e => e.OrderId).Hide();
            col.Bind(e => e.SiteId).Hide();
            col.Bind(e => e.DishId).Hide();
            col.Bind(e => e.Date).Hide();
            col.BindEnum(e => e.Category, "DishType").Width(60);
            col.Bind(e => e.Name).Width(100).Align(GridAlign.Left);
            col.BindControl(m => m.OrderCount, GridControlType.Label).Width(60).Align(GridAlign.Right);
            col.BindControl(m => m.SurplusCount).Width(60).Align(GridAlign.Right);
            col.BindControl(m => m.SellMoney).Width(60).Align(GridAlign.Right);
            col.BindControl(m => m.SellCount).Width(60).Align(GridAlign.Right);
        });
    }))
}
<script type="text/javascript">
    $(function () {
        $("#RevenueList").delegate("#RevenueList input[name='SurplusCount']", 'change', function (e) {
            var $this = $(this);
            var tr = $this.closest("tr");
            var inputOrder = tr.find("input[name='OrderCount']");
            var inputSell = tr.find("input[name='SellCount']");
            inputSell.val(parseFloat(inputOrder.val()) - parseFloat($this.val()));
            e.preventDefault();

            AutoSum();
        })
    });

    function AutoSum() {
        var data = $("#RevenueList").flexGetData();
        var TotalCost = 0;
        for (var i = 0; i < data.length; i++) {
            var Cost = data[i].SellMoney;
            var Count = data[i].SellCount;
            TotalCost += Cost * Count;
        }
        $('#SellAmount').val(parseFloat(TotalCost).toFixed(2));
    }  
</script>
